/* Colluding Against Workers: Appendix
	Delabastita & Rubens 
------------------------------------------*/
 
 *  global bs = 3

clear
set more off
cd "$station"
 
use ./data/temp/tempap, clear 
set matsize 1000
 
/* A. Production function: robustness checks */

** 1/ Baseline model

drop *bb1

gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})      )      , ///
inst(  L.lemp  L.lwm  L.lk lk L.lsegers  )  conv_maxiter(50) 
 
mat coef = e(b)
mat list coef
gen rho_bb1 = coef[1,1]
gen bl_bb1 = coef[1,2]
gen bm_bb1 = coef[1,3]
gen bk_bb1 = coef[1,4]
gen bc_bb1 = coef[1,5]
gen blm_bb1  = .
gen blk_bb1 = .

gen thl_bb1 = bl_bb1  
gen thm_bb1 = bm_bb1  

gen scale_bb1 = thl_bb1 +  thm_bb1 + bk_bb1  

** 1b. Baseline model fixing returns to scale 

forvalues n = 0(5)15 {
local nu = 1 +`n'/100
gen nu`n' = `nu'
gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -(`nu'-{bl}-{bm})*(lk - {rho}*L.lk)      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})      )      , ///
inst(  L.lemp  L.lwm  L.lk lk L.lsegers  )  conv_maxiter(50) 
 
local N_nu`n' = e(N)

 
mat coef = e(b)
mat list coef
gen rho_nu`n' = coef[1,1]
gen bl_nu`n' = coef[1,2]
gen bm_nu`n' = coef[1,3]
gen bk_nu`n' = 1-bl_nu`n'-bm_nu`n'
gen bc_nu`n' = coef[1,4]
gen blm_nu`n'  = .
gen blk_nu`n' = .

gen thl_nu`n' = bl_nu`n' 
gen thm_nu`n' = bm_nu`n'  

gen mu_nu`n' = bm_nu`n' /am 
gen md_nu`n' = (bl_nu`n' /al)/mu_nu`n' 


  estat overid 

  
 local j  = string(r(J)  ) 		 
local j_nu`n' = substr("`j'" ,1,4) 

local jp  = string(r(J_p)  ) 		 
local jp_nu`n' = substr("`jp'" ,1,4) 


}


forvalues n = 0(5)15 {
foreach var in "bl" "bm" "bk"  {
gen `var'_nu = `var'_nu`n'
}

foreach var in "md" "mu"  {
egen `var'_nu = median(`var'_nu`n')
}

estpost su bl_nu  bm_nu  bk_nu  md_nu  mu_nu 
est store pf_nu`n'
drop bl_nu  bm_nu  bk_nu  md_nu  mu_nu 
}

egen md_nu = median(md_nu5)

sum md_nu 

 



  

** 2/ Interaction effect materials and labor

gen lemplk = lemp*lk
gen lwmlk = lwm*lk

* OLS

reg lq lemp lwm  lk lemplk  lwmlk

mat coef = e(b)
mat list coef
gen bl_ols2 = coef[1,1]
gen bm_ols2 = coef[1,2]
gen bk_ols2 = coef[1,3]
gen blk_ols2 = coef[1,4]
gen bmk_ols2 = coef[1,5]
gen bc_ols2 = coef[1,6]

gen thl_ols2 = bl_ols2   + blk_ols2 * lk
gen thm_ols2 = bm_ols2   
gen scale_ols2 = thl_ols2 +  thm_ols2 + bk_ols2

local r2 = string(e(r2)) 		 
local r2_ols2 = substr("`r2'" ,1,4) 
 
* GMM

gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk) ///
 -({blk})*(lemplk - {rho}*L.lemplk)   -({bmk})*(lwmlk - {rho}*L.lwmlk)      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})    )      , ///
inst(  L.lemp  L.lwm L.lemplk L.lwmlk   L.lsegers L.lk lk  )  conv_maxiter(50) //technique(bfgs)

mat coef = e(b)
mat list coef
gen rho_bb2 = coef[1,1]
gen bl_bb2 = coef[1,2]
gen bm_bb2 = coef[1,3]
gen bk_bb2 = coef[1,4]
gen blk_bb2 = coef[1,5]
gen bmk_bb2 = coef[1,6]
gen bc_bb2 = coef[1,7]

gen thl_bb2 = bl_bb2  + blk_bb2 * lk
gen thm_bb2 = bm_bb2   + bmk_bb2 * lk
gen scale_bb2 = thl_bb2 +  thm_bb2 + bk_bb2  
 

* R-squared
preserve 
xtset mineid yr
gen tfp = lq - bl_bb2*lemp-bk_bb2*lk - bc_bb2 -bm_bb2*lwm - blk_bb2*lemplk - bmk_bb2*lwmlk
keep if tfp~=. & L.tfp~=.
gen qhat = tfp-lq
reg qhat lq 
egen avy = mean(lq)
egen tss = sum((lq-avy)^2)
egen rss = sum(tfp^2)
gen r2 = 1 - rss/tss
local r2 = string(r2) 		
di `r2'
local r2_gmm2 = substr("`r2'" ,1,4) 
restore

gen ltfp2 = lq - bl_bb2*lemp-bk_bb2*lk - bc_bb2 -bm_bb2*lwm  - blk_bb2*lemplk  
gen tfp2 = exp(ltfp2)



** 3/ Translog production function  

xtset mineid yr
gen Llklemp =  lk*L.lemp
gen Llklwm =  lk*L.lwm
 gen lemplwm = lemp*lwm
foreach var of varlist lemp lwm lk {
 gen `var'2 = `var'^2	
}
   
gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)     -({bk})*(lk - {rho}*L.lk) ///
  -({blk})*(lemplk - {rho}*L.lemplk)  -({blm})*(lemplwm - {rho}*L.lemplwm) -({bmk})*(lwmlk - {rho}*L.lwmlk) ///		 
 -({bl2})*(lemp2 - {rho}*L.lemp2) -({bm2})*(lwm2 - {rho}*L.lwm2) -({bk2})*(lk2 - {rho}*L.lk2)     ///		 
   -{bc}*(1 - {rho})         ) , ///
inst(  L.lemp  L.lwm L.lk lk  L.lsegers  L.lemplk L.lemplwm L.lwmlk   Llklemp Llklwm  L.lemp2 L.lwm2 lk2 L.lk2)  conv_maxiter(50) 
 

mat coef = e(b)
mat list coef
gen bl_bb3 = coef[1,2]
gen bm_bb3 = coef[1,3]
gen bk_bb3 = coef[1,4]
gen blk_bb3 = coef[1,5]
gen blm_bb3 = coef[1,6]
gen bmk_bb3 = coef[1,7]
gen bl2_bb3 = coef[1,8]
gen bm2_bb3 = coef[1,9]
gen bk2_bb3 = coef[1,10]

gen thl_bb3 = bl_bb3 + blm_bb3 * lwm + blk_bb3 * lk + bl2_bb3 * 2 *lemp 
gen thm_bb3 = bm_bb3  + blm_bb3 * lemp + bmk_bb3*lk + bm2_bb3 * 2*lwm 

estpost su bl_bb3 bm_bb3 bk_bb3 blk_bb3 blm_bb3 bmk_bb3 bl2_bb3 bm2_bb3 bk2_bb3 
est store pf3_bb
 
  
** 4/ Time-varying production function

* Two time blocks (1845-1879, 1880-1913)	 

gen blockbis1 = yr >=1845 & yr<=1879
gen blockbis2 = yr >=1880 & yr<=1913
 
gen bl_bb4 = .
gen bm_bb4 = .
gen bk_bb4 = .


gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)       ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})    )    if blockbis1==1  , ///
inst(  L.lemp  L.lwm   L.lsegers   L.lk lk  )  conv_maxiter(100) technique(bfgs)	// does converge using BFGS


mat coef = e(b)
mat list coef
replace bl_bb4 = coef[1,2] if blockbis1==1
replace bm_bb4 = coef[1,3] if blockbis1==1 
replace bk_bb4 = coef[1,4] if blockbis1==1

gen bl_blockbis1 = coef[1,2]
gen bm_blockbis1 = coef[1,3]
gen bk_blockbis1 = coef[1,4]
 
gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)       ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})    )    if blockbis2==1  , ///
inst(  L.lemp  L.lwm    L.lsegers  L.lk lk  )  conv_maxiter(100) technique(bfgs)
mat coef = e(b)
mat list coef
replace bl_bb4 = coef[1,2] if blockbis2==1
replace bm_bb4 = coef[1,3] if blockbis2==1
replace bk_bb4 = coef[1,4] if blockbis2==1

gen bl_blockbis2 = coef[1,2]
gen bm_blockbis2 = coef[1,3]
gen bk_blockbis2 = coef[1,4]
 
gen thl_bb4 = bl_bb4  
gen thm_bb4 = bm_bb4  
 
** 5/ Time-varying coefficients: interaction effects on beta_l

gen lempyr= lemp*yr 
gen lwmyr = lwm*yr 
gen lkyr = lk*yr
   
gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)       ///		// equation (8) with blk = 0
 -{blt}*(lempyr - {rho}*L.lempyr)         -{bt}*(yr - {rho}*L.yr)      -{bc}*(1 - {rho})    )     , ///
inst(  L.lemp  L.lwm   L.lsegers     L.lk lk yr L.lempyr     )  conv_maxiter(50) //technique(bfgs)
mat coef = e(b)
mat list coef
gen bl_bb5 = coef[1,2]  
gen bm_bb5 = coef[1,3]   
gen bk_bb5 = coef[1,4]   
gen blt_bb5 = coef[1,5] 
gen bt_bb5 = coef[1,6] 
 
gen thl_bb5 = bl_bb5 + blt_bb5*yr
gen thm_bb5 = bm_bb5  

sum thl_bb5 
  
twoway connect thl_bb5 yr 

 
** 6/ Linear time trend in productivity 
  
gen bl_bb6 = .
gen bm_bb6 = .
gen bk_bb6 = .
  
gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)   -({bt})*(yr - {rho}*L.yr)            ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})    )     , ///
inst(  L.lemp  L.lwm  L.lsegers  yr  L.yr L.lk lk  )  conv_maxiter(50) //technique(bfgs)
mat coef = e(b)
mat list coef

gen rho_bb6 = coef[1,1]  
replace bl_bb6 = coef[1,2]  
replace bm_bb6 = coef[1,3]   
replace bk_bb6 = coef[1,4]  
 
gen thl_bb6 = bl_bb6  
gen thm_bb6 = bm_bb6  
local N_bb6 = e(N)   

estat overid 
local j  = string(r(J)  ) 		 
local j_bb6 = substr("`j'" ,1,4) 
local jp  = string(r(J_p)  ) 		 
local jp_bb6 = substr("`jp'" ,1,4) 

 
** 7/ Unobserved input prices - DLGKP 2016 (ECMA)

gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)       ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})        -{bp}*(lp - {rho}*L.lp) )     , ///
inst(  L.lemp  L.lwm  L.lsegers      L.lk lk lp L.lp)  conv_maxiter(50) //technique(bfgs)
    	
mat coef = e(b)
mat list coef
gen rho_bb7 = coef[1,1]  
gen bl_bb7 = coef[1,2]  
gen bm_bb7 = coef[1,3] 
gen bk_bb7 = coef[1,4] 
gen bc_bb7 = coef[1,5] 

gen thl_bb7 = bl_bb7  
gen thm_bb7 = bm_bb7 

  
local N_bb7 = e(N)
preserve 
xtset mineid yr
gen tfp = lq - bl_bb7*lemp-bk_bb7*lk - bc_bb7 -bm_bb7*lwm  
keep if tfp~=. & L.tfp~=.
gen qhat = tfp-lq
reg qhat lq 
egen avy = mean(lq)
egen tss = sum((lq-avy)^2)
egen rss = sum(tfp^2)
gen r2 = 1 - rss/tss
local r2 = string(r2) 	
di `r2'
local r2_bb7 = substr("`r2'" ,1,4) 
restore
 

** 8/ Revenue production function (treuren)

gen lrev= log(p*q)

gen lwl = log(wl)

gmm (lrev - {rho}*L.lrev -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)       ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})         )     , ///
inst(  L.lemp  L.lwm   L.lsegers    L.lk lk  )  conv_maxiter(50) //technique(bfgs)
 
 
 
mat coef = e(b)
mat list coef
gen rho_bb8 = coef[1,1]  
gen bl_bb8 = coef[1,2]  
gen bm_bb8 = coef[1,3] 
gen bk_bb8 = coef[1,4] 
gen bc_bb8 = coef[1,5] 

gen thl_bb8 = bl_bb8  
gen thm_bb8 = bm_bb8  

estat overid
local j  = string(r(J)  ) 		 
local j_bb8 = substr("`j'" ,1,4) 
local jp  = string(r(J_p)  ) 		 
local jp_bb8 = substr("`jp'" ,1,4) 

  
  
preserve 
xtset mineid yr
gen tfp = lrev - bl_bb8*lemp-bk_bb8*lk - bc_bb8 -bm_bb8*lwm  
keep if tfp~=. & L.tfp~=.
gen revhat = tfp-lrev
reg revhat lrev 
egen avy = mean(lrev)
egen tss = sum((lrev-avy)^2)
egen rss = sum(tfp^2)
gen r2 = 1 - rss/tss
local r2 = string(r2) 		 
di `r2'
local r2_bb8 = substr("`r2'" ,1,4) 
restore

local N_bb8 = e(N)

  
** 9/ Quality control
 
foreach var of varlist q_leans_tot_t   {
gen s`var' = `var'/q
gen ls`var'= log(s`var')
}
replace sq_leans_tot_t = 0 if sq_leans_tot_t ==.


 
 


reg ltfp1 lsq_lean 
xtreg ltfp1 lsq_lean , fe r

gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)       ///		// equation (8) with blk = 0
 -{bs}*(sq_leans_tot_t - {rho}*L.sq_leans_tot_t)    -{bc}*(1 - {rho})         )     , ///
inst(  L.lemp  L.lwm    L.lsegers    L.lk lk sq_leans_tot_t L.sq_leans_tot_t )  conv_maxiter(50) //technique(bfgs)
  
  
  
mat coef = e(b)
mat list coef
gen rho_bb9 = coef[1,1]  
gen bl_bb9 = coef[1,2]  
gen bm_bb9 = coef[1,3] 
gen bk_bb9 = coef[1,4] 
gen bc_bb9 = coef[1,6] 

gen thl_bb9 = bl_bb9  
gen thm_bb9 = bm_bb9  


preserve 
xtset mineid yr
gen tfp = lq - bl_bb9*lemp-bk_bb9*lk - bc_bb9 -bm_bb9*lwm  
keep if tfp~=. & L.tfp~=.
gen qhat = tfp-lq
reg qhat lq 
egen avy = mean(lq)
egen tss = sum((lq-avy)^2)
egen rss = sum(tfp^2)
gen r2 = 1 - rss/tss
local r2 = string(r2) 		 
di `r2'
local r2_bb9 = substr("`r2'" ,1,4) 
restore
local N_bb9 = e(N)



** 10/ serial correlation = 1
  
gmm (lq -  L.lq -{bl}*(lemp - L.lemp)     -({bm})*(lwm -  L.lwm)   -({bk})*(lk -  L.lk)       ///		// equation (8) with blk = 0
           )     , ///
inst(  L.lemp  L.lwm  L.lsegers     L.lk lk   )  conv_maxiter(50) //technique(bfgs)

mat coef = e(b)
mat list coef
gen rho_bb10 = 1
 gen bl_bb10 = coef[1,1]  
gen bm_bb10 = coef[1,2] 
gen bk_bb10 = coef[1,3] 
 
gen thl_bb10 = bl_bb10  
gen thm_bb10 = bm_bb10
estat overid 
  local j  = string(r(J)  ) 		 
local j_bb10 = substr("`j'" ,1,4) 
local jp  = string(r(J_p)  ) 		 
local jp_bb10 = substr("`jp'" ,1,4) 


preserve 
xtset mineid yr
gen tfp = lq - bl_bb10*lemp-bk_bb10*lk   -bm_bb10*lwm  
keep if tfp~=. & L.tfp~=.
gen qhat = tfp-lq
reg qhat lq 
egen avy = mean(lq)
egen tss = sum((lq-avy)^2)
egen rss = sum(tfp^2)
gen r2 = 1 - rss/tss
local r2 = string(r2) 		 
di `r2'
local r2_bb10 = substr("`r2'" ,1,4) 
restore
local N_bb10 = e(N)

  
 
** 11/ Estimate production function without agricultural wage 

gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})      )      , ///
inst(  L.lemp  L.lwm  L.lk lk   )  conv_maxiter(50) technique(bfgs)
 
mat coef = e(b)
mat list coef
gen rho_bb11 = coef[1,1]
gen bl_bb11 = coef[1,2]
gen bm_bb11 = coef[1,3]
gen bk_bb11 = coef[1,4]
gen bc_bb11 = coef[1,5]
gen blm_bb11  = .
gen blk_bb11 = .

gen thl_bb11 = bl_bb11  
gen thm_bb11 = bm_bb11  

gen scale_bb11 = thl_bb11 +  thm_bb11 + bk_bb11 

* estimate with agricultural shocks themselves. 

gen limp_p_isic = log(imp_p_isic)	// log import price of agricultural products 
gen limp_p_keygrains = log(imp_p_keygrains)	// log import price of key grain products 
gen lprod_agri = log(agriculturalproduct/agr_emp_imputed)

* regress agricultural wage on agricultural productivity and import competition

 
bys yr: egen emp_coal = sum(emp)
bys yr: egen wl_coal = sum(wl)
gen uwl_coal = wl_coal/emp_coal

gen luwl_coal = log(uwl_coal)
gen lemp_coal = log(emp_coal)

preserve 
collapse lsegers lprod_agri limp_p_keygrains limp_p_isic luwl_coal , by(yr)
reg lsegers lprod_agri limp_p_keygrains limp_p_isic	yr , r	// get this into table. 
gen bprod = _b[lprod_agri]
gen bimp = _b[limp_p_keygrains]
gen seprod = _se[lprod_agri]
gen seimp = _se[limp_p_keygrains]

local N_agri_wage = e(N)
local r2  = string(e(r2))
local r2_agri_wage= substr("`r2'",1,4)


estpost su bprod bimp 
est store agri_wage
replace bprod = seprod 
replace bimp = seimp 

estpost su bprod bimp 
est store agri_wage_se


restore 
* get t 

reg luwl_coal lprod_agri limp_p_keygrains 



* i. main IV

gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})      )      , ///
inst(  L.lemp  L.lwm  L.lk lk  L.lsegers  )  conv_maxiter(50)  
mat coef = e(b)
mat list coef
gen rho_iv1 = coef[1,1]
gen bl_iv1 = coef[1,2]
gen bm_iv1 = coef[1,3]
gen bk_iv1 = coef[1,4]


 * ii. no instrument 

gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})      )      , ///
inst(  L.lemp  L.lwm  L.lk lk   )  conv_maxiter(50)   technique(bfgs)
mat coef = e(b)
mat list coef
gen rho_iv2 = coef[1,1]
gen bl_iv2 = coef[1,2]
gen bm_iv2 = coef[1,3]
gen bk_iv2 = coef[1,4]


* iii. agricultural productivity

gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})      )      , ///
inst(  L.lemp  L.lwm  L.lk lk    L.limp_p_keygrains   L.lprod_agri  )  conv_maxiter(50)  


mat coef = e(b)
mat list coef
gen rho_iv3 = coef[1,1]
gen bl_iv3 = coef[1,2]
gen bm_iv3 = coef[1,3]
gen bk_iv3 = coef[1,4]


* save results to table

foreach var in "l" "k" "m" {
forvalues n = 1/3 { 
gen b_iv`n' = b`var'_iv`n' 
}
estpost su b_iv1 b_iv2 b_iv3  
drop b_iv* 
est store b`var'_iv 
 }

  forvalues m = 1/3 {
gen mu_iv`m' = bm_iv`m' /am 
gen md_iv`m' = (bl_iv`m' /al)/mu_iv`m' 
}

forvalues n = 1/3 {
 gen kappa_iv`n' = (md_iv`n'- psic_dq4    )/( psim_dq4 - psic_dq4) 
bys yr: egen medkappa_iv`n' = median(kappa_iv`n')
 	}	

	label var medkappa_iv1 "IV = agri. wage"
	label var medkappa_iv2 "No additional IV"
	label var medkappa_iv3 "IV = agri. import price  and productivity"
	
twoway connect medkappa_iv1 medkappa_iv2 medkappa_iv3   yr ,  lpattern(solid longdash shortdash "-." "..")  msize(medium medium medium medium medium) msymbol(circle square triangle diamond X) lcolor(navy maroon green purple black) mfcolor(white white white white white) mcolor(navy maroon green purple black)   graphregion(color(white)) xline(1898, lcolor(red) lpattern(shortdash)) ytitle("Collusion index") xtitle("Year") xscale(titlegap(*5))
 graph export ./output/fig/fig_medcol_iv.pdf, replace

 

  
** 12/ AR(2) production function

gmm (lq - {rho}*L.lq - {rho2}*L2.lq -{bl}*(lemp - {rho}*L.lemp - {rho2}*L2.lemp)     -({bm})*(lwm - {rho}*L.lwm - {rho2}*L2.lwm)   -({bk})*(lk - {rho}*L.lk - {rho2}*L2.lk) ///
      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho} - {rho2})    )      , ///
inst(  L.lemp L2.lemp  L.lwm L2.lwm    L.lsegers L2.lsegers L.lk lk  L2.lk )  conv_maxiter(50) //technique(bfgs)

mat coef = e(b)
mat list coef
drop *bb12
gen rho1_bb12 = coef[1,1]
gen rho2_bb12 = coef[1,2]
gen bl_bb12 = coef[1,3]
gen bm_bb12 = coef[1,4]
gen bk_bb12 = coef[1,5]
gen bc_bb12 = coef[1,6]
local N_bb12 = e(N)
gen thl_bb12 = bl_bb12  
gen thm_bb12 = bm_bb12  

foreach var in "bl" "bm" "bk" "rho1" "rho2" {
	gen `var' = `var'_bb12
}

estpost su bl  bm  bk  rho1 rho2 
est store pf_bb12
drop bl bm bk rho1 rho2 
 
gen ltfp_bb12 = lq - bl_bb12*lemp - bk_bb12*lk - bc_bb12 -bm_bb12*lwm 
xtset mineid yr
gen nu_bb12 = ltfp_bb12 - rho1_bb1 * L.ltfp_bb12 - rho2_bb1 * L2.ltfp_bb12
reg nu_bb12 L.nu_bb12, nocons


** Compute markdowns and markups 
   
  forvalues m = 1/12 {
gen mu_bb`m' = thm_bb`m' /am 
gen md_bb`m' = (thl_bb`m' /al)/mu_bb`m' 
}

drop md_bb8 mu_bb8 	// rev pf - markdowns computed differently and markup not identified

gen mdl_bb8 = (bl_bb8 /al) 
gen mdm_bb8 = (bm_bb8 /am)

sum mdm_bb8, d
gen mu_bb8 = .
gen md_bb8 = mdl_bb8 
sum mdl* mdm* 

 

*** LABOR SUPPLY: ROBUSTNESS CHECKS
   
*** Test for employer differentiation

 
gen demshock = yr>= 1871 & yr<= 1875
gen p98 = yr>=1898
gen e_car_p98 = e_car*p98

* install packages for IV regression with FEs
/*
ssc install ranktest
ssc install ivreg2, replace
ssc install ivreghdfe
ssc install reghdfe 
ssc install ftools
*/


ivregress 2sls luw (lemp  = demshock e_car_p98  )  e_car p98    , r

gen bwf1 = _b[lemp]
gen sewf1  =  _se[lemp]
local N  = string(e(N))
local N_labdif1 = substr("`N'",1,4)

areg lemp demshock e_car_p98 e_car p98, absorb(dq4id)
local F  = string(e(F))
local F_labdif1  = substr("`F'",1,3)

ivreghdfe luw (lemp  = demshock e_car_p98  )  e_car p98    , absorb(mid) r
gen bwf2 = _b[lemp]
gen sewf2  =  _se[lemp]
local N  = string(e(N))
local N_labdif2 = substr("`N'",1,5)

areg lemp demshock e_car_p98 e_car p98, absorb(mid)
local F  = string(e(F))
local F_labdif2  = substr("`F'",1,4)

* with market-level employment

gen lemp_dq4 = log(emp_dq4) 

ivregress 2sls luw (lemp_dq4  = demshock e_car_p98  )  e_car p98    
gen bwf3 = _b[lemp]
gen sewf3  =  _se[lemp]
local N  = string(e(N))
local N_labdif3 = substr("`N'",1,4)

areg lemp_dq4 demshock e_car_p98 e_car p98, absorb(dq4id)
local F  = string(e(F))
local F_labdif3  = substr("`F'",1,3)

ivreghdfe luw (lemp_dq4  = demshock e_car_p98  )  e_car p98    , absorb(mid)
gen bwf4 = _b[lemp]
gen sewf4  =  _se[lemp]
local N  = string(e(N))
local N_labdif4 = substr("`N'",1,5)

areg lemp_dq4 demshock e_car_p98 e_car p98, absorb(mid)
local F  = string(e(F))
local F_labdif4  = substr("`F'",1,4)



* save to table 

gen bwf = .

forvalues m = 1/4 {
replace bwf = bwf`m' 
estpost su bwf 
est store labdif`m' 
replace bwf = sewf`m' 
estpost su bwf
est store labdif`m'_se 
}

label var bwf  "log(Employment)"
esttab labdif1 labdif1_se labdif2 labdif2_se using ./output/tab/table_labdif.tex, replace  ///
mtitle("Est." "S.E." "Est." "S.E.") nolines prehead( \textit{ } &  \multicolumn{2}{c}{ log(Wage)}   &  \multicolumn{2}{c}{ log(Wage)}     \\ )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot( &&&&\\   Market-Year FE &	\multicolumn{2}{c}{No} &	\multicolumn{2}{c}{Yes} \\ ///
First-stage F-statistic &	\multicolumn{2}{c}{`F_labdif1'} &	\multicolumn{2}{c}{`F_labdif2'}\\  ///
  Observations &	\multicolumn{2}{c}{`N_labdif1'} &	\multicolumn{2}{c}{`N_labdif2'} \\ ///
 \hline    )  posthead( \hline  &&&\\   ) 
  

 
 
** Table time-varying production elasticities



forvalues m = 1/2 {
gen b`m' = . 
}

forvalues m = 1/2 {
replace b`m' = bl_bb4 if blockbis`m'==1
}
estpost su b1  b2   
est store bl_timev1 

forvalues m = 1/2 {
replace b`m' = bm_bb4 if blockbis`m'==1
}
estpost su b1  b2   
est store bm_timev1 

forvalues m = 1/2 {
replace b`m' = bk_bb4 if blockbis`m'==1
}
estpost su b1  b2   
est store bk_timev1 

** Table with linear production function  

  
 
* Time-varying labor supply elasticity

 
local m = 4
preserve
collapse(sum) emp wl  drail dtram e_union dunion dcar e_car impp cpi   degreve*, by(dq`m'id    yr )
 
gen block1 = yr<1880
gen p98 = yr>=1898
gen limpp = log(impp)
gen dcar_p98 = dcar*p98
gen e_car_p98 = e_car*p98
gen demshock = yr>= 1871 & yr<= 1875
gen lemp = log(emp)
gen luw = log(wl/emp)
gen lqimp = log(degreve_imp_q)
gen pimp = (degreve_imp_p/cpi)
gen lpimp = log(pimp)

reg lqimp lpimp
predict demshock2, resid

gen ptrans =  ((degreve_trans_pq/degreve_trans_q)/cpi)
gen lptrans = log(ptrans)
  
 ivregress 2sls luw (lemp    =  demshock e_car_p98     )     p98   e_car , r
 
 ivregress 2sls luw (lemp    =  demshock e_car_p98     )     p98   e_car   if yr<1880 , r
local bw_block1 = _b[lemp]
local sew_block1 = _se[lemp]
 
 ivregress 2sls luw (lemp    =  demshock e_car_p98     )     p98   e_car   if yr>=1880 , r
local bw_block2 = _b[lemp]
local sew_block2 = _se[lemp]

  
local r2 = string(e(r2)) 		
local r2_tv1 = substr("`r2'" ,1,4) 
local N_tv1 = e(N)
 
 
* Interaction effect 

gen lempyr = lemp*yr 
gen demshock_yr = demshock*yr 
gen e_car_p98_yr = e_car_p98*yr
ivregress 2sls luw (lemp lempyr =  demshock  e_car_p98   )  demshock_yr  e_car_p98_yr  yr  p98   e_car , r      
local bw_tv3 = _b[lemp]
local bwt_tv3 = _b[lempyr]
local sew_tv3 = _se[lemp]
local sewt_tv3 = _se[lempyr]
local r2 = string(e(r2)) 		
local r2_tv3 = substr("`r2'" ,1,4) 
local N_tv3 = e(N)

 
* linear time trend 

ivregress 2sls luw (lemp =  demshock  e_car_p98  ) yr  p98   e_car , r 
local bw_tv2 = _b[lemp]
local sew_tv2 = _se[lemp]
local r2 = string(e(r2)) 		
local r2_tv2 = substr("`r2'" ,1,4) 
local N_tv2 = e(N)
local bt_tv2 = _b[yr]
local set_tv2 = _se[yr]
restore 


gen thw_tv1 = `bw_block1'  if yr<1880
replace thw_tv1 = `bw_block2' if yr>=1880

gen thw_tv2 = `bw_tv2'  
gen thw_tv3 = `bw_tv3' + `bwt_tv3'*yr

 
forvalues n = 1/3 {
forvalues m = 4/4 {
gen psic_tv`n' = 1+thw_tv`n'*semp_dq`m'
gen psim_tv`n' = 1+thw_tv`n'
gen kappa_tv`n' = (md_bb1- psic_tv`n'    )/( psim_tv`n' - psic_tv`n') 
foreach var in "psic" "psim" "kappa" {
bys yr: egen av`var'_tv`n' = mean(`var'_tv`n')
bys yr: egen med`var'_tv`n' = median(`var'_tv`n')
}
}
}

label var yr "Year"
label var medkappa_dq4 "Main model"
label var medkappa_tv1 "Time-trend in labor residual"
label var medkappa_tv2 "Time-block labor coefficients"
label var medkappa_tv3 "Time trend in labor coefficient"
sort yr
 twoway connect medkappa_dq4 medkappa_tv1 medkappa_tv2 medkappa_tv3 yr ,  lpattern(solid longdash shortdash "-." "..")  msize(medium medium medium medium medium) msymbol(circle square triangle diamond X) lcolor(navy maroon green purple black) mfcolor(white white white white white) mcolor(navy maroon green purple black)   graphregion(color(white)) xline(1898, lcolor(red) lpattern(shortdash)) ytitle("Collusion index") xscale(titlegap(*5))
 graph export ./output/fig/fig_medcol_tv.pdf, replace
 
* Labor supply robustness checks

preserve 
local m = 4
collapse(sum) emp wl drail dtram e_union dcar e_car (mean) cpi segers*  degreve*  , by(dq`m'id   yr)
gen p98 = yr>=1898
gen dcar_p98 = dcar*p98
gen e_car_p98 = e_car*p98
gen demshock = yr>= 1871 & yr<= 1875
gen lemp = log(emp)
gen luw = log(wl/emp)
gen lqimp = log(degreve_imp_q)
gen pimp = (degreve_imp_p/cpi)
gen lpimp = log(pimp)
gen lsegers  = log(segers_nomwage_agr/cpi)
gen lcpi = log(cpi)  
 
reg lqimp lpimp
predict demshock2, resid

gen ptrans =  ((degreve_trans_pq/degreve_trans_q)/cpi)
gen lptrans = log(ptrans)

reg luw lemp e_car p98 demshock e_car_p98
local becar_ols_dq`m' = _b[e_car]
local bp98_ols_dq`m' = _b[p98]
local bw_ols_dq`m' = _b[lemp]
local sew_ols_dq`m' = _se[lemp]

* sample sizes

di _N 	
gen dumobs = 0
replace dumobs = 1 if lemp  ~=. & luw ~=. & e_car ~=. & p98 ~=. & demshock  ~=. & e_car_p98 ~=.  
tab dumobs		
 

ivregress 2sls luw (lemp =  demshock  e_car_p98  )  e_car p98    

ivregress 2sls luw (lemp =     e_car_p98   )  e_car p98  , first  
local bw_iv_dq`m'_rob4 = _b[lemp]

ivregress 2sls luw (lemp =     demshock  )  e_car p98 , first   
local bw_iv_dq`m'_rob1 = _b[lemp]


replace demshock = yr>= 1871 & yr<= 1874
ivregress 2sls luw (lemp =     demshock  e_car_p98  )  e_car p98    
local bw_iv_dq`m'_rob2 = _b[lemp]

replace demshock = yr>= 1871 & yr<= 1876
ivregress 2sls luw (lemp =     demshock  e_car_p98  )  e_car p98    
local bw_iv_dq`m'_rob3 = _b[lemp]

restore 

forvalues n = 1/4 {
gen bw_iv_dq4_rob`n' = `bw_iv_dq4_rob`n''
}

forvalues n = 1/4 {
gen psic_dq4_rob`n' = 1+bw_iv_dq4_rob`n'*semp_dq4
gen psim_dq4_rob`n' = 1+bw_iv_dq4_rob`n'
}  

foreach var of varlist psic_dq4_rob* psim_dq4_rob* {
bys yr: egen med`var' = median(`var')
}


 
 
 
twoway line medpsic_dq4 medpsim_dq4  yr , lpattern(solid solid solid)  lcolor(navy navy navy) mfcolor(white white white) msize(medium msmall medium) msymbol(circle diamond square)  graphregion(color(white)) ///
|| line medpsic_dq4_rob1 medpsim_dq4_rob1 yr, lpattern(longdash longdash longdash) lcolor(maroon maroon maroon) mfcolor(white white white) msize(medium msmall medium) msymbol(circle diamond square)  graphregion(color(white))  ///
|| line medpsic_dq4_rob4 medpsim_dq4_rob4 yr, lpattern(shortdash shortdash shortdash) lcolor(green green green) mfcolor(white white white) msize(medium msmall medium) msymbol(circle diamond square)  graphregion(color(white))  /// 
|| connect medmd_bb1 yr, lpattern(solid) lcolor(black ) mcolor(black) mfcolor(white) ///
 xscale(titlegap(*5)) ylabel(,angle(horizontal))  legend(order(7 "Markdown" 1 "Both IVs" 3 "Only coal price surge IV" 5 "Only cartel IV" )) ytitle("Markdown")
 graph export ./output/fig/fig_mmd_rob1.pdf, replace
 

twoway line medpsic_dq4 medpsim_dq4  yr , lpattern(solid solid solid)  lcolor(navy navy navy) mfcolor(white white white) msize(medium msmall medium) msymbol(circle diamond square)  graphregion(color(white)) ///
|| line medpsic_dq4_rob2 medpsim_dq4_rob2 yr, lpattern(longdash longdash longdash) lcolor(maroon maroon maroon) mfcolor(white white white) msize(medium msmall medium) msymbol(circle diamond square)  graphregion(color(white))  ///
|| line medpsic_dq4_rob3 medpsim_dq4_rob3 yr, lpattern(shortdash shortdash shortdash ) lcolor(green green green) mfcolor(white white white) msize(medium msmall medium) msymbol(circle diamond square)  graphregion(color(white))  ///
|| connect medmd_bb1 yr, lpattern(solid) lcolor(black ) mcolor(black) mfcolor(white) ///
 xscale(titlegap(*5)) ylabel(,angle(horizontal)) legend(order(7 "Markdown" 1 "Shock = 1871-1875" 3 "Shock = 1871-1874" 5 "Shock = 1871-1876")) ytitle("Markdown")
 graph export ./output/fig/fig_mmd_rob2.pdf, replace
 
  
 
* save estimates to table 

gen bw1 = `bw_block1' 
gen bw2 = `bw_block2' 
estpost su bw1 bw2
est store bw_timev1 
replace bw1 = `sew_block1' 
replace bw2 = `sew_block2'  
estpost su bw1 bw2
est store bw_timev1_se 

gen bt = `bt_tv2'
replace bw = `bw_tv2' 
 estpost su bw  bt
est store bw_timev2 
replace bw = `sew_tv2'  
replace bt = `set_tv2'
 estpost su bw  bt
est store bw_timev2_se 
 
gen bwt = `bwt_tv3'
replace bw = `bw_tv3' 
 estpost su bw  bwt
est store bw_timev3 
replace bw = `sew_tv3'  
replace bwt = `sewt_tv3'
 estpost su bw  bwt
est store bw_timev3_se 

 
 
 label var bw "log(Employment)"
 label var bw1 "log(Employment) (1845-1879)"
 label var bw2 "log(Employment) (1880-1913)"
 label var bt "Year"
 label var bwt "log(Employment)*Year"
 
 esttab bw_timev1 bw_timev1_se bw_timev2 bw_timev2_se bw_timev3 bw_timev3_se using ./output/tab/table_labsup_tv.tex, replace  ///
mtitle("Est." "S.E.""Est." "S.E." "Est." "S.E." ) nolines prehead(   &  \multicolumn{2}{c}{ log(Wage) } &  \multicolumn{2}{c}{  log(Wage)} &  \multicolumn{2}{c}{  log(Wage)}   \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot( Observations & \multicolumn{2}{c}{ `N_tv1'} & \multicolumn{2}{c}{ `N_tv2'} & \multicolumn{2}{c}{ `N_tv3'}    \\  \hline  \\ &&      )  posthead(    &&\\ \hline  ) 


 * interaction effects

gen b = bl_bb5
estpost su b  
est store bl_timev3
replace b = blt_bb5
estpost su b  
est store blt_timev3
replace b = bt_bb5
estpost su b  
est store bt_timev3
drop b

** Different weighting


foreach var of varlist wm wl emp {
bys yr: egen `var'_yr = sum(`var')
gen s`var'_yr = `var'/`var'_yr	
bys yr: egen check_`var' = sum(s`var'_yr)
sum check_`var'
gen wmd_s`var' = md_bb1*s`var'_yr
gen wkappa_s`var' = kappa_dq4*s`var'_yr
bys yr: egen agmd_s`var' = sum(wmd_s`var')
bys yr: egen agkappa_s`var' = sum(wkappa_s`var')
}

sort yr
label var agmd_swl "Wage bill share weighted"
label var agmd_semp "Employment share weighted"
twoway connect  agmd_swl agmd_semp yr , lpattern(shortdash longdash) msymbol(square diamond) mfcolor(white white) xline(1898, lwidth(medthick) lpattern(longdash) lcolor(orange_red)) graphregion(color(white)) ytitle("Markdown") xscale(titlegap(*5)) ylabel(,angle(horizontal)) 
 graph export ./output/fig/fig_md_weights.pdf, replace

label var agkappa_swl "Wage bill share weighted"
label var agkappa_semp "Employment share weighted"

twoway connect  agkappa_swl agkappa_semp yr , lpattern(shortdash longdash) msymbol(square diamond) mfcolor(white white) xline(1898, lwidth(medthick) lpattern(longdash) lcolor(orange_red)) graphregion(color(white)) ytitle("Collusion index") xscale(titlegap(*5)) ylabel(,angle(horizontal)) 
 graph export ./output/fig/fig_kappa_weights.pdf, replace

  
  
** Other robustness checks


* Productivity innovations serially correlated?
 
gen ltfp_bb1 = lq - bl_bb1*lemp-bk_bb1*lk - bc_bb1 -bm_bb1*lwm  

xtset mineid yr
gen nu_bb1 =  ltfp_bb1 - rho_bb1*L.ltfp_bb1 
reg nu_bb1 L.nu_bb1, nocons

gen bnu = _b[L.nu]
estpost su bnu 
est store bnu 

local N_bnu = e(N)
local r2 = string(e(r2)) 		 
local r2_bnu = substr("`r2'" ,1,4) 

* What happens if \rho = 1?

gmm (lq -  L.lq -{bl}*(lemp -  L.lemp)     -({bm})*(lwm -L.lwm)   -({bk})*(lk -  L.lk)       ///		// equation (8) with blk = 0
   )      , ///
inst(  L.lemp  L.lwm   L.lsegers     L.lk lk  )  conv_maxiter(50) //technique(bfgs)

* Add linear time trend
 
gmm (lq - {rho}*L.lq -{bl}*(lemp - {rho}*L.lemp)     -({bm})*(lwm - {rho}*L.lwm)   -({bk})*(lk - {rho}*L.lk)   -({bt})*(yr - {rho}*L.yr)      ///		// equation (8) with blk = 0
   -{bc}*(1 - {rho})    )      , ///
inst(  L.lemp  L.lwm    L.lsegers     L.lk lk  yr)  conv_maxiter(50) //technique(bfgs)

 
 


* store table estimates
 
* drop rho
forvalues n = 6/11 {
	gen bl = bl_bb`n'
	gen bk = bk_bb`n'
	gen bm = bm_bb`n'
	gen rho = rho_bb`n'
estpost su bl bm bk rho 
est store pf_bb`n'
drop bl bm bk rho
	}	
	
forvalues n = 1/1 {
	gen bl = bl_bb`n'
	gen bk = bk_bb`n'
	gen bm = bm_bb`n'
	gen rho = rho_bb`n'
estpost su bl bm bk rho 
est store pf_bb`n'
drop bl bm bk rho
	}	
	

	
forvalues n = 1/11 {
gen mu = mu_bb`n'
gen md = md_bb`n'
estpost su md mu
est store mu_bb`n'
drop mu md
	}	

  
forvalues n = 1/11 {
 gen kappa_bb`n' = (md_bb`n'- psic_dq4    )/( psim_dq4 - psic_dq4) 
bys yr: egen medkappa_bb`n' = median(kappa_bb`n')
 	}	
	
	
	sum md*
	
	forvalues n = 0(5)15 {
gen kappa_nu`n' = (md_nu`n'- psic_dq4    )/( psim_dq4 - psic_dq4) 
bys yr: egen medkappa_nu`n' = median(kappa_nu`n')
 	}	

label var medkappa_nu0 "RTS = 1.00"	
label var medkappa_nu5 "RTS = 1.05"	
label var medkappa_nu10 "RTS = 1.10"	
label var medkappa_nu15 "RTS = 1.15"	
	
twoway connect medkappa_nu0  medkappa_nu5  medkappa_nu10  medkappa_nu15       yr , ///
lpattern(solid longdash shortdash "-." "..")  msize(medium medium medium medium medium) msymbol(circle square triangle diamond X) lcolor(navy maroon green purple black) mfcolor(white white white white white) mcolor(navy maroon green purple black)   graphregion(color(white)) xline(1898, lcolor(red) lpattern(shortdash)) ytitle("Collusion index")
graph export ./output/fig/fig_medcol_robnu.pdf, replace

 

	
/* collusion estimate using different models 
1 baseline
2 input interaction terms
3 translog
4 2 time blocks
5 linear trend in beta_l
6 time trend tfp
7 DLGKP 
8 RPF
9 quality control 
10	serial correlation 1
*/


label var medkappa_bb1 "Main model"
label var medkappa_bb3 "Translog"
label var medkappa_bb4 "Two time blocks"
label var medkappa_bb5 "Time trend in beta_l"
label var medkappa_bb6 "Time trend in TFP"
label var medkappa_bb7 "Price control"
label var medkappa_bb8 "RPF"
label var medkappa_bb9 "Quality control"
label var medkappa_bb10 "First differences"

twoway connect medkappa_bb1  medkappa_bb3   medkappa_bb4  medkappa_bb5    medkappa_bb6      yr , ///
lpattern(solid longdash shortdash "-." "..")  msize(medium medium medium medium medium) msymbol(circle square triangle diamond X) lcolor(navy maroon green purple black) mfcolor(white white white white white) mcolor(navy maroon green purple black)   graphregion(color(white)) xline(1898, lcolor(red) lpattern(shortdash)) ytitle("Collusion index")
graph export ./output/fig/fig_medcol_rob1.pdf, replace
 
 twoway connect medkappa_bb1  medkappa_bb7  medkappa_bb9  medkappa_bb8    medkappa_bb10 yr , ///
lpattern(solid longdash shortdash "-." "..")  msize(medium medium medium medium medium) msymbol(circle square triangle diamond X) lcolor(navy maroon green purple black) mfcolor(white white white white white) mcolor(navy maroon green purple black)   graphregion(color(white)) xline(1898, lcolor(red) lpattern(shortdash)) ytitle("Collusion index")
graph export ./output/fig/fig_medcol_rob2.pdf, replace
 
 
 
 
* interaction effects

foreach mod in "ols" "bb" {
foreach var in "bl" "bm" "bk"  "blk"   "bmk" "thm" "thl" "scale"{
gen `var' = `var'_`mod'2
}
estpost su bl bm bk     blk bmk
est store pf_`mod'2
estpost su thl thm scale 
est store th_`mod'2
drop bl bm bk    thl scale thm   blk bmk
}

* Cost shares approach - robustness check
 
gen rts = 1	// returns to scale parameter
gen bl_cs_col = rts*(wl*psim_dq4/(wm + wl*psim_dq4 + winv)) 
gen bm_cs_col = rts*(wm/(wm + wl*psim_dq4 + winv)) 
gen bk_cs_col = rts - bl_cs_col - bm_cs_col

gen bl_cs_noc = rts*(wl*psic_dq4/(wm + wl*psic_dq4+ winv)) 
gen bm_cs_noc = rts*(wm/(wm + wl*psic_dq4+ winv)) 
gen bk_cs_noc = rts - bl_cs_noc - bm_cs_noc
 
sum bl_cs_col bl_cs_noc, d
sum bm_cs_col bm_cs_noc, d

gen mu_cs_noc = bm_cs_noc / am
gen mu_cs_col = bm_cs_col / am

sum mu_cs*
 
foreach var in "l" "k" "m" {
gen col = b`var'_cs_col 
gen noc = b`var'_cs_noc

estpost su col noc
est store bcs_`var'
drop col noc
}

gen col = mu_cs_col 
gen noc = mu_cs_noc 
estpost su      col noc 
est store mu_cs
drop col noc

* Bertrand - simple logit

sum pop
bys dq4id yr: egen pop_dq4 = mean(pop) 	// pop comes at dq4 level
drop emp_dq4
bys dq4id yr: egen nemp_dq4 = sum(emp/ndays)

gen nemp = emp/ndays

drop semp_dq4 lsemp_dq4 
gen semp_dq4 = nemp/pop_dq4
gen lsemp_dq4 = log(nemp/pop_dq4)
gen oo_dq4 = (pop_dq4-nemp_dq4) /pop_dq4
gen loo_dq4  = log(oo_dq4)

gen lhs_dq4  = lsemp_dq4 - loo_dq4 
drop uw
gen uw = wl/emp		// daily wage 
gen uwn = wl/nemp	// annual wage
reg lhs_dq4   uw
drop luw
gen luw = log(uw)
gen luwn = log(uwn)


ivregress 2sls  lhs_dq4 (uw   = demshock e_car_p98) e_car p98  , r
gen bw_lin = _b[uw]
gen sew_lin = _se[uw] 
gen md_lin = (bw_lin*uw*(1-semp_dq4))^(-1)+1
sum md_lin, d

local r2  = string(e(r2))
local r2_lin = substr("`r2'",1,4)
local N_lin = e(N)

di `N_lin' 

ivregress 2sls  lhs_dq4 (luw = demshock e_car_p98) e_car p98  , r

gen limpp = log(impp)
ivregress 2sls  lhs_dq4 (luw = demshock e_car_p98 limpp) e_car p98  , r

gen bw_con = _b[luw]
gen sew_con = _se[luw]
gen md_con = (bw_con*(1-semp_dq4))^(-1)+1
sum md_con, d
local r2  = string(e(r2))
local r2_con = substr("`r2'",1,4)
local N_con = e(N)

gmm (lhs_dq4  - {bl}*luw - {bcar}*e_car - {b98}*p98  -{bc} )            , ///
inst( demshock e_car_p98 e_car p98 )  

  
sum md_lin md_con*

gmm (lhs_dq4  - {bl}*(log(uw - {b})) - {bcar}*e_car - {b98}*p98 -{bc}  )            , ///
inst( demshock e_car_p98 e_car p98 limpp ) from(bl 0.8 b 1  )  
 
mat coef = e(b)
mat list coef
mat Vcoef = e(V)
mat list Vcoef
 
gen bw_cchk = coef[1,1]
gen sew_cchk = sqrt(Vcoef[1,1])
gen bb_cchk = coef[1,2]
gen seb_cchk = sqrt(Vcoef[2,2])
 
gen md_cchk = (bw_con*(uw/(uw-bb_cchk))*(1-semp_dq4))^(-1)+1
sum md_cchk, d
local r2  = string(e(r2))
local r2_cchk = substr("`r2'",1,4)
local N_cchk = e(N)

 
gen sew = .
gen bb = . 
 
foreach var in "lin" "con" {
replace bw = bw_`var' 
estpost su bw 
est store bw_`var'
replace bw = sew_`var' 
estpost su bw 
est store bw_`var'_se
}
 
foreach var in "cchk" {
replace bw = bw_`var' 
replace bb = bb_`var'
estpost su bw bb 
est store bw_`var'
replace bw = sew_`var' 
replace bb = seb_`var' 
estpost su bw bb
est store bw_`var'_se
}

gen  md = .
 
foreach var in "lin" "con" "cchk" {
egen amd_`var' = mean(md_`var')
egen mmd_`var' = median(md_`var')
}
 

foreach var in "lin" "con"  "cchk" {
replace md = amd_`var' 
estpost su md 
est store amd_`var'
replace md = mmd_`var'
estpost su md  
est store mmd_`var' 
}
 

* Fully collusive markdown: need to solve for equilibrium wage under full collusion

gen kappa_dq4_lin = md_bb1 / md_lin
gen kappa_dq4_con = md_bb1 / md_con
gen kappa_dq4_cchk = md_bb1 / md_cchk

sum kappa_dq4_lin kappa_dq4_con kappa_dq4_cchk, d

foreach var of varlist kappa_dq4_con kappa_dq4_lin kappa_dq4_cchk {
bys yr: egen med`var' = median(`var')	
bys yr: egen av`var' = mean(`var')	
}

label var medkappa_dq4_con "Markdown/non-collusive markdown"
label var medkappa_dq4_lin "Markdown/non-collusive markdown"
  
 * comparison bertrand and cournot model
 label var medkappa_dq4_lin "Differentiated employers (linear)"
 label var medkappa_dq4_con "Differentiated employers (concave)"
 label var medkappa_dq4_cchk "Differentiated employers (alt. wage)"
 
bys yr: egen medkappa_dq4_hom = median(md_bb1/psic_dq4)
 
 label var medkappa_dq4_hom "Homogeneous employers"

  twoway connect medkappa_dq4_con medkappa_dq4_lin medkappa_dq4_cchk medkappa_dq4_hom yr, xline(1897, lpattern(shortdash)) graphregion(color(white)) ///
  lpattern(solid longdash shortdash "-." "..")  msize(medium medium medium medium medium) msymbol(circle square triangle diamond X) lcolor(navy maroon green purple black) mfcolor(white white white white white) mcolor(navy maroon green purple black) ytitle("Markdown/non-collusive markdown") xscale(titlegap(*5)) legend(col(1))
  graph export ./output/fig/fig_medcol_bertrand.pdf, replace


* Include outside option 
drop nemp_dq4 nemp
gen nemp = emp/ndays
bys dq4id yr: egen nemp_dq4 = sum(emp/ndays)
gen semp_pop_dq4 = nemp  / (pop_dq4/3)
gen sempcoal_pop_dq4 = nemp_dq4 / (pop_dq4/3)

gen psic_oo  = 1+bw_iv_dq4 *semp_pop_dq4
gen psim_oo  = 1+bw_iv_dq4 *sempcoal_pop_dq4

sum psic_oo psic_dq4 
sum psim_oo psim_dq4
 
   
/* C. Markups and markdowns
--------------------------------*/
 
   
 
forvalues m = 1(1)12 {
foreach var in  "md_bb" "mu_bb"   {
bys yr: egen  med`var'`m' = median(`var'`m')
bys yr: egen  av`var'`m' = mean(`var'`m')
gen s`var'`m' = `var'`m'*sempag
bys yr: egen  ag`var'`m' = sum(s`var'`m')
}
}

 
* Store markup moments for translog and interaction term model
 
 forvalues m = 1/3 {
 gen med = medmd_bb`m'
 gen av = avmd_bb`m'
 gen ag = agmd_bb`m'

estpost su med  
est store md`m'_bb
 
replace med = medmu_bb`m'
replace av = avmu_bb`m'
replace ag = agmu_bb`m'


estpost su med  
est store mu`m'_bb
drop med av ag 
 }

 
* Robustness: markups and cartel

gen lmu_bb1 = log(mu_bb1)
reg lmu_bb1 e_car e_car_p98 p98 	// yes markup increases at cartel firms after 1898
gen mucar1 = _b[e_car_p98] 
local r2  = string(e(r2))
local r2_mucar1 = substr("`r2'",1,4)
local N_mucar1 = e(N)

areg lmu_bb1 e_car e_car_p98 p98 , absorb(mine_id)	// yes markup increases at cartel firms after 1898
gen mucar2 = _b[e_car_p98] 
local r2  = string(e(r2))
local r2_mucar2 = substr("`r2'",1,4)
local N_mucar2 = e(N)

gen mucar = mucar1 
estpost su mucar 
est store mucar1 
replace mucar = mucar2 
estpost su mucar 
est store mucar2 
 
 
** Cost dynamics

xtset mineid yr
gen qcum = 0
forvalues m = 1/72 {
replace qcum = qcum+ L`m'.q if L`m'.q~=. 
}

gen lqcum = log(qcum)
label var lqcum "log(Cum. output)"
label var ltfp1 "log(TFP)"
 twoway scatter ltfp1 lqcum , msize(medium) mcolor(white) mlcolor(navy) ylabel(,angle(horizontal)) graphregion(color(white)) xscale(titlegap(*5))
graph export ./output/fig/fig_costdyn.pdf, replace 
 
bys mineid: egen startyr = min(yr)
gen age = yr-startyr
gen lage = log(age)
reg ltfp1 lqcum lage i.yr, r


********************************************************************************




* Robustness: differentiate markups by cost shares (calculate markups without outliers)
  
 **** Cost shares
egen totalw = rowtotal(wl wm winv)
gen csl = wl/totalw
gen csm = wm/totalw
gen csinv = winv/totalw
 
 global varlist "csl csm csinv"
 foreach x in $varlist {
	bys yr: egen plow = pctile(`x'), p(10)
	bys yr: egen phigh = pctile(`x'), p(90)
	gen o_`x'10 = (plow < `x' & phigh > `x')
	drop plow phigh
	bys yr: egen plow = pctile(`x'), p(25)
	bys yr: egen phigh = pctile(`x'), p(75)
	gen o_`x'25 = (plow < `x' & phigh > `x')
	drop plow phigh
 }
 
foreach k of numlist 10 25 {
egen ort`k' = rowtotal(o_csl`k'  o_csm`k'  o_csinv`k' )
gen mu1_trim`k'  = mu_bb1
replace mu1_trim`k'  = . if ort`k' !=3
bys yr: egen avmu1_trim`k'  = mean(mu1_trim`k' )
}
label variable avmu_bb1 "Main sample"
label variable avmu1_trim10 "Trimmed sample"
scatter avmu_bb1 avmu1_trim10 yr, connect(direct direct) graphregion(color(white))  lpattern(solid longdash)  msize(medium medium) msymbol(circle square ) lcolor(navy maroon) mfcolor(white white) mcolor(navy maroon) ///
	ytitle("Markup") ylabel(,angle(horizontal))
	
twoway kdensity avmu_bb1 || kdensity avmu1_trim10, legend(order(1 "Main sample" 2 "Trimmed sample")) graphregion(color(white)) xtitle(Markup) ylabel(,angle(horizontal)) xline(1, lcolor(red))
graph export ./output/fig/fig_avmu_trim.pdf, replace

**** Write table
label variable avmu1_trim10 "Trimmed sample (p10)"
label variable avmu1_trim25 "Trimmed sample (p25)"
estpost summarize ///
    avmu_bb1 avmu1_trim10 avmu1_trim25, detail
esttab using ./output/tab/table_avmu_trim.tex, cells("min(fmt(2)) p10(fmt(2)) p25(fmt(2)) mean(fmt(2)) p75(fmt(2)) p90(fmt(2)) max(fmt(2))") label nodepvar replace ///
 collabels("Min." "p10" "p25" "Mean" "p75" "p90" "Max.") nolines ///
 booktabs nonum gaps f noobs   ///
prefoot(  \hline    )  posthead( \hline  \\   ) 

	
	 









** Bootstrapped standard errors
do dr_appendix_bs
 
** Tables
 
** compile tables

* bertrand models

*gen bw = .
gen bb = .
gen md = .
label var bw "Wage coefficient, $\alpha$"
label var md "Non-coll. markdown $\underline{\mu^l}$"
label var bb "Outside option, b"

 
esttab bw_lin bw_lin_se bw_con bw_con_se bw_cchk bw_cchk_se  using ./output/tab/table_bertrand.tex, replace  ///
mtitle("Est." "S.E." "Est." "S.E." "Est." "S.E."  ) nolines prehead( "\textit{Panel A: Labor supply }" &  \multicolumn{2}{c}{ Linear U. } &  \multicolumn{2}{c}{ Concave U.}  &  \multicolumn{2}{c}{ Alt. wage}   \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot(Observations & \multicolumn{2}{c}{ `N_lin'} & \multicolumn{2}{c}{ `N_con'} & \multicolumn{2}{c}{ `N_cchk'}    \\&& \\ \hline     )  posthead(    &&\\ \hline  ) 

 
esttab amd_lin mmd_lin  amd_con mmd_con amd_cchk mmd_cchk using ./output/tab/table_bertrand.tex, append  ///
mtitle("Average" "Median""Average" "Median"  "Average" "Median" ) nolines prehead(    ///
"\textit{Panel B:  Markdown}" & \multicolumn{2}{c}{ Linear U. } &  \multicolumn{2}{c}{ Concave U.}  &  \multicolumn{2}{c}{ Alt. wage}   \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot(&&& \\  \hline  \\ &&      )  posthead(    &&\\ \hline  ) 
 
 
** Table fixing returns to scale

foreach var in "bl" "bm" "bk" "md" "mu" {
gen `var'_nu = .
} 
label var bl_nu "Labor" 
label var bm_nu "Materials" 
label var bk_nu "Capital" 
label var mu_nu "Median price markup" 
label var md_nu "Median wage markdown" 
  
esttab pf_nu0 pf_nu0_se   pf_nu10 pf_nu10_se pf_nu15 pf_nu15_se  using ./output/tab/table_pfnu.tex, replace  ///
mtitle("Est." "S.E."   "Est." "S.E." "Est." "S.E." ) nolines prehead( \textit{ } &  \multicolumn{2}{c}{   \$\varsigma\$ = 1  }     &  \multicolumn{2}{c}{  \$\varsigma\$ = 1.10 }  &  \multicolumn{2}{c}{  \$\varsigma\$ = 1.15 }    \\ )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot( &&&&\\     ///
Hansen J-test &	\multicolumn{2}{c}{`j_nu0'} & 	\multicolumn{2}{c}{`j_nu10'} &	\multicolumn{2}{c}{`j_nu15'}\\  Hansen J-test p-value &	\multicolumn{2}{c}{`jp_nu0'}     &	\multicolumn{2}{c}{`jp_nu10'}&	\multicolumn{2}{c}{`jp_nu15'} ///
\\    Observations &	\multicolumn{2}{c}{`N_nu0'}  &	\multicolumn{2}{c}{`N_nu10'}  &	\multicolumn{2}{c}{`N_nu15'} \\ ///
 \hline    )  posthead( \hline  &&&\\   ) 
  
 
 
* Serial correlation nu 
  
foreach var in "bnu" "bl" "bm" "bk" "rho1" "rho2" {
	gen `var'=.
}
 
label var bnu "Lagged productivity shock"
label var bl "log(Labor)"
label var bm "log(Materials)"
label var bk "log(Capital)"
label var rho1 "One-year TFP correlation"
label var rho2 "Two-year TFP correlation"


esttab bnu bnu_se using ./output/tab/table_bnu.tex, replace  ///
mtitle("Est." "S.E."   ) nolines prehead( \textit{Panel A: Serial correlation of productivity shocks in AR(1) model}  &  \multicolumn{2}{c}{ Productivity shock }     \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot(&&     \\ ///
Observations & \multicolumn{2}{c}{ `N_bnu'}    \\&& \\ \hline     )  posthead(    &&\\ \hline  ) 

esttab pf_bb12 pf_bb12_se using ./output/tab/table_bnu.tex, append  ///
mtitle("Est." "S.E."   ) nolines prehead( \textit{Panel B: Production function coefficients in AR(2) model}  &  \multicolumn{2}{c}{log(Output) }     \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot(&&\\ Observations & \multicolumn{2}{c}{ `N_bb12'}    \\&& \\ \hline     )  posthead(    &&\\ \hline  ) 

 * Agricultural wage instruments 

forvalues n = 1/3 { 
gen b_iv`n' = . 
}

label var b_iv1 "Agricultural wage"
label var b_iv2 "No additional IV"
label var b_iv3 "Ag. wage drivers"

	esttab bl_iv bl_iv_se bm_iv bm_iv_se bk_iv bk_iv_se using ./output/tab/table_b_iv.tex, replace  ///
	mtitle("Est." "S.E." "Est." "S.E."  "Est." "S.E.") nolines prehead(\textit{Panel A: Production coefficients} &  \multicolumn{2}{c}{ Labor }   &  \multicolumn{2}{c}{ Materials}  &  \multicolumn{2}{c}{ Capital }      \\ )    ///
	cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
	prefoot( &&&&\\   \hline    )  posthead( \hline  &&&\\ \textit{Additional instruments:} &&&&\vspace{0.5em} \\   ) 

gen bprod = .
gen bimp = .
label var bprod "Ag. labor productivity"
label var bimp "Ag. import price"
 
  esttab agri_wage agri_wage_se  using ./output/tab/table_b_iv.tex, append  ///
mtitle("Est." "S.E." ) nolines prehead( \textit{Panel B: Ag. wage drivers} &  \multicolumn{2}{c}{ log(Ag. wage)}     \\ )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot( &&\\  ///
R-squared &	\multicolumn{2}{c}{`r2_agri_wage'} \\  ///
  Observations &	\multicolumn{2}{c}{`N_agri_wage'}  \\ ///
 \hline    )  posthead( \hline  &&\\   ) 
 
* Comparison PF estimation with and without agricultural wage instrument

gen mu = .
gen rho = .
label var md "Average markdown"
label var mu "Average markup"
label var rho "Serial correlation"

esttab pf_bb1 pf_bb1_se pf_bb11 pf_bb11_se    using ./output/tab/table_wagecontrol.tex, replace ///
mtitle("Est." "S.E." "Est." "S.E.") prehead(   \textit{ Panel A: Production function }  & \multicolumn{2}{c}{log(Output)} & \multicolumn{2}{c}{log(Output)} \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot( &&&&\\ Method &	\multicolumn{2}{c}{GMM} &	\multicolumn{2}{c}{GMM}  ///
\\  Agricultural wage instrument &	\multicolumn{2}{c}{Yes} &	\multicolumn{2}{c}{No}  ///
 \\  Observations &	\multicolumn{2}{c}{`N_gmm1'} &	\multicolumn{2}{c}{`N_gmm11'} \\ &&&&\\  \hline )  posthead( \hline  &&&\\   ) 

 esttab mu_bb1 mu_bb1_se mu_bb11 mu_bb11_se    using ./output/tab/table_wagecontrol.tex, append ///
mtitle("Est." "S.E." "Est." "S.E.") prehead(   \textit{Panel B: Markups/ markdowns  }  & \multicolumn{2}{c}{ } & \multicolumn{2}{c}{ } \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot( &&&&\\ Method &	\multicolumn{2}{c}{GMM} &	\multicolumn{2}{c}{GMM}  ///
\\  Agricultural wage instrument &	\multicolumn{2}{c}{Yes} &	\multicolumn{2}{c}{No}  ///
 \\  Observations &	\multicolumn{2}{c}{`N_gmm1'} &	\multicolumn{2}{c}{`N_gmm11'} \\ &&&&\\  \hline )  posthead( \hline  &&&\\   ) 
drop mu rho
  
* 2 time blocks 
  
forvalues m = 1/2 {
gen b`m' = . 
}
label var b1 "1845-1879: "  
label var b2 "1880-1913:"
  
esttab bl_timev1 bl_timev1_se bm_timev1 bm_timev1_se bk_timev1 bk_timev1_se using ./output/tab/table_pf_timev.tex, replace  ///
mtitle("Est." "S.E.""Est." "S.E." "Est." "S.E.") nolines prehead( "\textit{Panel A: Two time blocks}" &  \multicolumn{2}{c}{ Labor } &  \multicolumn{2}{c}{ Materials }  &  \multicolumn{2}{c}{ Capital }   \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot( && \\  \hline     )  posthead(    &&\\ \hline  ) 

drop b1 b2 

* time trend in labor coefficient

gen b = .
label var b "Coefficient:"
 
esttab bl_timev3 bl_timev3_se blt_timev3 blt_timev3_se bt_timev3 bt_timev3_se using ./output/tab/table_pf_timev.tex, append  ///
mtitle("Est." "S.E.""Est." "S.E." "Est." "S.E.") nolines prehead( "\textit{Panel B: time trend in labor coefficient}" &  \multicolumn{2}{c}{ Labor } &  \multicolumn{2}{c}{ Labor*Year }  &  \multicolumn{2}{c}{ Year }   \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot( && \\  \hline     )  posthead(    &&\\ \hline  ) 
drop b

* time trend in TFP

gen b = .
label var b "Coefficient:"

esttab bl_timev3 bl_timev3_se blt_timev3 blt_timev3_se bt_timev3 bt_timev3_se using ./output/tab/table_pf_timev.tex, append  ///
mtitle("Est." "S.E.""Est." "S.E." "Est." "S.E.") nolines prehead( "\textit{Panel C: time trend in productivity}" &  \multicolumn{2}{c}{ Labor } &  \multicolumn{2}{c}{ Labor*Year }  &  \multicolumn{2}{c}{ Year }   \\    )    ///
cells(mean(fmt(3))  ) label booktabs nonum collabels(none) gaps f   noobs   ///
prefoot( && \\  \hline     )  posthead(    &&\\ \hline  ) 
 
* Translog production function

label var bl_bb3 "log(Labor)"
label var bm_bb3 "log(Materials)"
label var bk_bb3 "log(Capital)"
label var blk_bb3 "log(Labor)*log(Capital)"
label var bmk_bb3 "log(Materials)*log(Capital)"
label var blm_bb3 "log(Labor)*log(Materials)"
label var bl2_bb3 "log(Labor)*log(Labor)"
label var bk2_bb3 "log(Capital)*log(Capital)"
label var bm2_bb3 "log(Materials)*log(Materials)"

gen mu = .
label var mu "Average markup"
label var md "Average markdown"

esttab pf3_bb pf3_bb_se      using ./output/tab/table_apmu.tex, replace ///
 mtitle("Est." "S.E." "Est." "S.E.") prehead( \textit{Panel A: Production coefficients }    &  \multicolumn{2}{c}{ }             \\     )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(  &&\\  \hline      )  posthead( \hline   &&\\   ) 
 
esttab   mu_bb3 mu_bb3_se    using ./output/tab/table_apmu.tex, append ///
 mtitle("Est." "S.E." "Est." "S.E.") prehead( \textit{Panel B: Markups/markdowns }    &  \multicolumn{2}{c}{ }         \\     )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(  &&\\    \hline    )  posthead( \hline   &&\\   )  



* Cost shares production function
 
gen col = .
gen noc  = .

label var col "Perfect collusion" 
label var noc  "No collusion" 
 
esttab bcs_l bl_cs_se bcs_m bm_cs_se bcs_k bk_cs_se    using ./output/tab/table_cs.tex, replace ///
 mtitle("Est." "S.E." "Est." "S.E." "Est." "S.E.") prehead( \textit{Panel A: Output elasticities }    &  \multicolumn{2}{c}{Labor}   &  \multicolumn{2}{c}{Materials}     &  \multicolumn{2}{c}{Capital}     \\     )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(  &&\\      \hline  )  posthead( \hline   &&\\   ) 

gen mu_cs_noc = .
gen mu_cs_col = .

label var mu_cs_col "Perfect collusion" 
label var mu_cs_noc "No collusion" 

esttab mu_cs mu_cs_se    using ./output/tab/table_cs.tex, append ///
 mtitle("Est." "S.E."  ) prehead( \textit{Panel B: Markup }    &  \multicolumn{2}{c}{Markup}      \\     )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(  &&\\   \hline     )  posthead( \hline   &&\\   )  

* Rev PF 

gen rho = . 
  
label var bl "log(Labor)"
label var bm "log(Materials)"
label var bk "log(Capital)"
label var rho "Serial correlation"
label var mu "Average markup"
label var md "Average markdown"




esttab pf_bb8 pf_bb8_se pf_bb10 pf_bb10_se pf_bb6 pf_bb6_se   using ./output/tab/table_revpf.tex, replace ///
 mtitle("Est." "S.E." "Est." "S.E." "Est." "S.E."  ) prehead( \textit{Panel A: Output elasticities}    &  \multicolumn{2}{c}{log(Revenue)}   &  \multicolumn{2}{c}{log(Output)}  &  \multicolumn{2}{c}{log(Output)}   \\     )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(    &&\\ Method &  \multicolumn{2}{c}{R.P.F.}   & \multicolumn{2}{c}{$\rho = 1$}    & \multicolumn{2}{c}{Time trend}     ///
/*\\ R-squared &  \multicolumn{2}{c}{`r2_bb8'}  & \multicolumn{2}{c}{`r2_bb10'}     */ /// 
\\  Hansen J-test &	\multicolumn{2}{c}{`j_bb8'} &	\multicolumn{2}{c}{`j_bb10'} &	\multicolumn{2}{c}{`j_bb6'}\\  Hansen J-test p-value &	\multicolumn{2}{c}{`jp_bb8'}  &	\multicolumn{2}{c}{`jp_bb10'} &	\multicolumn{2}{c}{`jp_bb6'} ///
\\ Observations &  \multicolumn{2}{c}{`N_bb8'}   & \multicolumn{2}{c}{`N_bb10'}   & \multicolumn{2}{c}{`N_bb6'}  \\&&& \\ \hline  )  posthead( \hline   &&\\   ) 

esttab mu_bb8 mu_bb8_se mu_bb10 mu_bb10_se mu_bb6  mu_bb6_se    using ./output/tab/table_revpf.tex, append ///
 mtitle("Est." "S.E." "Est." "S.E."   "Est." "S.E." ) prehead( \\ \textit{Panel B: Markups }         )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(  &&\\   \hline    )  posthead( \hline  &&\\   ) 
 

esttab pf_bb7 pf_bb7_se pf_bb9 pf_bb9_se     using ./output/tab/table_difpf.tex, replace ///
 mtitle("Est." "S.E." "Est." "S.E."   ) prehead( \textit{Panel A: Output elasticities }    &  \multicolumn{2}{c}{log(Output)}   &  \multicolumn{2}{c}{log(Output)}   \\     )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(  &&\\ Method &  \multicolumn{2}{c}{Price control}   & \multicolumn{2}{c}{Quality control}    ///
\\ R-squared &  \multicolumn{2}{c}{`r2_bb7'}  & \multicolumn{2}{c}{`r2_bb9'}      ///
\\ Observations &  \multicolumn{2}{c}{`N_bb7'}   & \multicolumn{2}{c}{`N_bb9'}  \\&&& \\ \hline    )  posthead( \hline   &&\\   ) 

esttab mu_bb7 mu_bb7_se mu_bb9 mu_bb9_se    using ./output/tab/table_difpf.tex, append ///
 mtitle("Est." "S.E." "Est." "S.E."   ) prehead( \\ \textit{Panel B:  Markups }           )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(  &&\\  \hline    )  posthead( \hline  &&\\   ) 
 
 


 


* markups and cartel

gen mucar = .
label var mucar "1(Year$>$1897)*1(Cartel member)"
esttab mucar1 mucar1_se mucar2 mucar2_se    using ./output/tab/table_mucar.tex, replace ///
 mtitle("Est." "S.E." "Est." "S.E." ) prehead(      &  \multicolumn{2}{c}{log(Markup)}  &  \multicolumn{2}{c}{log(Markup)}    \\     )    ///
cells(mean(fmt(3))   ) label booktabs nonum collabels(none) gaps f   noobs ///
prefoot(  &&\\  Mine FE &  \multicolumn{2}{c}{No} & \multicolumn{2}{c}{Yes}  ///
\\ R-squared &  \multicolumn{2}{c}{`r2_mucar1'} & \multicolumn{2}{c}{`r2_mucar2'}      ///
\\ Observations &  \multicolumn{2}{c}{`N_mucar1'} & \multicolumn{2}{c}{`N_mucar2'}   &&\\  \hline        )  posthead( \hline   &&\\   ) 
 

 




/* D. Other robustness checks
--------------------------------*/


* Lamp oil cost share

use ./data/temp/data_pf, clear 
set matsize 10000
 	
sum k, d 
sum *_p* 
 
* lamp oil
preserve
use ./data/temp/petroleum.dta, clear 
keep if community == "Liège" | community == "Namur"
rename community province
replace province = "Liege" if province == "Liège"
collapse (mean) petr, by(province year)
encode province, gen(prov) 
drop province
reshape wide petr, i(year) j(prov) 
corr petr* // Very high correlation, so just use Liège prices, which have better availability
keep year petr1
rename petr1 ppetr
rename year yr
tempfile ppetr
save `ppetr'
restore

merge m:1 yr using `ppetr'
// underground labor ud
// materials wm


// Guesstimate lamp oil cost
gen wpetr = ud * 1.4 * 5.2 * ppetr
gen spetr = wpetr/wm

order wpetr spetr ud ppetr
sum spetr
sum spetr, d
